﻿package mortal.game.view.copy.sixBoss.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.event.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.copy.sixBoss.data.*;
    import mortal.game.view.copy.sixBoss.renderer.*;
    import mortal.game.view.copy.treasureHunt.renderer.*;
    import mortal.mvc.interfaces.*;

    public class SixBossInfoWin extends Window
    {
        private var _3dBg:GImageBitmap;
        private var _bossName:GTextFiled;
        private var _bossIntroduce:GTextFiled;
        private var _dropItemList:GTileList;
        private var _outPutList:GTileList;
        private var _ps:GTextFiled;
        private var _isKilledImg:GImageBitmap;
        private var _title:GTextFiled;
        private var _rect3d:Rect3DObject;
        private var _img2d:Img2D;
        private var _bossModel:ActionPlayer;
        private var _bossInfo:SMonsterSiegeBossInfo;
        private static var _instance:SixBossInfoWin;

        public function SixBossInfoWin(param1:ILayer = null)
        {
            super(param1);
            setSize(463, 443);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.init3dRect();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SixBossInfoBg, 0, 0, this));
            this._title = UIFactory.gTextField(Language.getString(40932), 0, 43, 472 - 12, 30 + 4, this, GlobalStyle.textFormatAnjin.setSize(20).center());
            this._3dBg = UIFactory.gImageBitmap(ImagesConst.ChallengeTip3Dbg, 252, 46 + 36, null, this.onBgLoadCompl);
            this.configEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
            this._bossName = UIFactory.gTextField("", 18, 83, 237, 25, this, GlobalStyle.textFormatChen.setSize(15).center());
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SixBossIntroduce, 26, 116, this));
            this._bossIntroduce = UIFactory.gTextField(Language.getString(40933), 26, 139, 225, 70, this, GlobalStyle.textFormatBai.setSize(13));
            this._bossIntroduce.multiline = true;
            this._bossIntroduce.wordWrap = true;
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SixBossDrop, 26, 212, this));
            this._isKilledImg = UIFactory.gImageBitmap("smallBossKilled.png", 255 + 12 - 6, 132 + 38, this.contentTopOf3DSprite);
            this._isKilledImg.visible = false;
            this._dropItemList = UIFactory.tileList(13, 243 + 8, 275, 45, this.contentTopOf3DSprite);
            this._dropItemList.columnWidth = 44;
            this._dropItemList.rowHeight = 43;
            this._dropItemList.horizontalGap = 0;
            this._dropItemList.verticalGap = 0;
            this._dropItemList.setStyle("skin", new Bitmap());
            this._dropItemList.setStyle("cellRenderer", TreasureRewardItemCellRenderer);
            this._outPutList = UIFactory.tileList(39, 331 + 3, 422, 108, this.contentTopOf3DSprite);
            this._outPutList.columnWidth = 211;
            this._outPutList.rowHeight = 34;
            this._outPutList.horizontalGap = 0;
            this._outPutList.verticalGap = 0;
            this._outPutList.setStyle("skin", new Bitmap());
            this._outPutList.setStyle("cellRenderer", SixBossOutPutInfoRenderer);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.SixBossInfoTip, 18 + 6, 306 + 5, this));
            this._ps = UIFactory.gTextField(Language.getString(40934), 37, 434, 433, 20, this, GlobalStyle.textFormatChen);
            return;
        }// end function

        override protected function updateBtnSize() : void
        {
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 20 + 9;
                _closeBtn.y = -23 + 78 - 6;
            }
            return;
        }// end function

        private function onBgLoadCompl() : void
        {
            if (this._img2d)
            {
                this._rect3d.removeImg(this._img2d);
            }
            this._img2d = new Img2D(null, this._3dBg.bitmapData, new Rectangle(0, 0, 201, 222), false);
            this._rect3d.addImg(this._img2d);
            return;
        }// end function

        private function init3dRect() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(252, 46 + 36, 201, 222), this);
            Rect3DManager.instance.windowShowHander(null, this);
            return;
        }// end function

        private function updateBossModel() : void
        {
            var _loc_2:String = null;
            var _loc_3:String = null;
            this.removeModel();
            var _loc_1:* = BossConfig.instance.getInfoByCode(this._bossInfo.bossCode);
            if (_loc_1)
            {
                _loc_2 = _loc_1.mesh + ".md5mesh";
                _loc_3 = _loc_1.bone + ".skeleton";
                this._bossModel = FrObjectPool.getObject(ActionPlayer, this);
                if (this._bossModel.meshUrl != _loc_2 && this._bossModel.animUrl != _loc_3)
                {
                    this._bossModel.load(_loc_2, _loc_3, _loc_1.texture);
                }
                FrEventDispatcher.instance.proxyAddEventListener(this._bossModel, Engine3dEventName.PARSE_MESH_FINISH, this.modleLoadedHandler);
                this._bossModel.changeAction(ActionName.Stand);
                this._bossModel.play();
                this._bossModel.rotationY = -15;
                this._bossModel.scaleValue = 0.8;
                this._rect3d.addObject3d(this._bossModel, 110 - 3, 184 - 22);
                this.updatePosition();
                this.dispatchEvent(new WindowEvent(WindowEvent.SHOW_END));
                if (this._bossInfo.lifePer == 0)
                {
                    this._isKilledImg.visible = true;
                }
                else
                {
                    this._isKilledImg.visible = false;
                }
            }
            return;
        }// end function

        public function updatePosition() : void
        {
            this.dispatchEvent(new WindowEvent(WindowEvent.POSITIONCHANGE));
            return;
        }// end function

        protected function modleLoadedHandler(param1 = null) : void
        {
            return;
        }// end function

        private function remove3D() : void
        {
            if (this._rect3d)
            {
                this._rect3d.disposeObj3d(this._img2d);
                this._img2d = null;
                this._rect3d.disposeObj3d(this._bossModel);
                this._bossModel = null;
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            return;
        }// end function

        private function removeModel() : void
        {
            if (this._rect3d)
            {
                this._rect3d.disposeObj3d(this._bossModel);
                this._bossModel = null;
            }
            return;
        }// end function

        public function set data(param1:SMonsterSiegeBossInfo) : void
        {
            this._bossInfo = param1;
            if (this._bossInfo)
            {
                this.updateAll();
            }
            return;
        }// end function

        private function updateAll() : void
        {
            this.updateBossName();
            this.updateBossIntroduce();
            this.updateBossDrop();
            this.updateBossModel();
            this.updateOutputList();
            return;
        }// end function

        private function updateBossName() : void
        {
            var _loc_1:* = BossConfig.instance.getInfoByCode(this._bossInfo.bossCode);
            if (_loc_1)
            {
                this._bossName.text = _loc_1.name;
            }
            return;
        }// end function

        private function updateBossIntroduce() : void
        {
            var _loc_2:String = null;
            var _loc_1:* = BossConfig.instance.getInfoByCode(this._bossInfo.bossCode);
            if (_loc_1)
            {
                _loc_2 = DescConfig.instance.getDescById(_loc_1.dialogId);
                this._bossIntroduce.text = _loc_2;
            }
            return;
        }// end function

        private function updateBossDrop() : void
        {
            var _loc_2:String = null;
            var _loc_3:DataProvider = null;
            var _loc_4:Array = null;
            var _loc_5:String = null;
            var _loc_1:* = CopyConfig.instance.getCopyInfoByCode(GameConst.SixBossCopyCode);
            if (_loc_1)
            {
                _loc_2 = _loc_1.rewardShow;
                if (_loc_2)
                {
                    _loc_3 = new DataProvider();
                    _loc_4 = _loc_2.split("#");
                    for each (_loc_5 in _loc_4)
                    {
                        
                        _loc_3.addItem(new ItemData(int(_loc_5)));
                    }
                    this._dropItemList.dataProvider = _loc_3;
                    this._dropItemList.drawNow();
                    this._dropItemList.x = (240 - this._dropItemList.columnWidth * this._dropItemList.length) / 2 + 2 + 17;
                }
            }
            return;
        }// end function

        private function updateOutputList() : void
        {
            var _loc_5:SixBossOutPutRewardInfo = null;
            var _loc_1:* = QuestionCopyConfig.instance().getRewardsByTypeAndTimes(7, this._bossInfo.bossCode);
            var _loc_2:Array = [];
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                if (!_loc_1[_loc_3].scoreMax)
                {
                    _loc_1[_loc_3].scoreMax = 0;
                }
                if (!_loc_1[_loc_3].scoreMin)
                {
                    _loc_1[_loc_3].scoreMin = 0;
                }
                if (_loc_1[_loc_3].scoreMax >= 0 && _loc_1[_loc_3].scoreMin >= 0)
                {
                    _loc_5 = new SixBossOutPutRewardInfo();
                    _loc_5.outPutIndex = _loc_3 + 1;
                    _loc_5.itemCode = int(_loc_1[_loc_3].itemRewards.split("#")[0]);
                    _loc_5.itemAmount = int(_loc_1[_loc_3].itemRewards.split("#")[1]);
                    _loc_2.push(_loc_5);
                }
                _loc_3++;
            }
            var _loc_4:* = new DataProvider();
            _loc_4.addItems(_loc_2);
            this._outPutList.dataProvider = _loc_4;
            this._outPutList.drawNow();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._3dBg.dispose();
            this._3dBg = null;
            this._bossName.dispose();
            this._bossName = null;
            this._bossIntroduce.dispose();
            this._bossIntroduce = null;
            this._dropItemList.dispose();
            this._dropItemList = null;
            this._outPutList.dispose();
            this._outPutList = null;
            this._ps.dispose();
            this._ps = null;
            this._isKilledImg.dispose();
            this._isKilledImg = null;
            this._title.dispose();
            this._title = null;
            this._bossInfo = null;
            this.remove3D();
            return;
        }// end function

        public static function get instance() : SixBossInfoWin
        {
            if (!_instance)
            {
                _instance = new SixBossInfoWin;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
